package com.woniu.dao;

import com.woniu.dto.GoodsAll;
import com.woniu.dto.OrderAndDetail;
import com.woniu.pojo.Orders;
import com.woniu.pojo.Property;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.data.annotation.Id;

public interface OrdersMapper {
    int deleteByPrimaryKey(Long id);

    int insert(Orders record);

    int insertSelective(Orders record);

    Orders selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Orders record);

    int updateByPrimaryKey(Orders record);

    @Select("select o.order_num,o.create_time,o.status,o.price as totalprice,o.deal," +
            "d.g_id,d.number,d.price,s.shipping_place,s.phone from orders o right join shipping s on o.user_id = s.user_id right join order_detail d on o.id = d.o_id where o.user_id = #{id}")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(column = "g_id",property = "goodsAll",one = @One(select = "findGoodsAll",fetchType = FetchType.EAGER))
    })
    OrderAndDetail getOrdersDetail(@Param("id") Long id);

    @Select("select g.title,g.description,g.price as oneprice,g.goods_type,d.goods_img from goods g right join goods_detail d on g.id=d.g_id where g.id=#{g_id}")
     GoodsAll findGoodsAll(@Param("gid") Long g_id);

    @Delete("update orders set status = 7 where user_id = #{id} ")
    int deleteByUserId(Long id);
}